package com.example.campuslink.commen.adpter

import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.core.CoreAdapter
import com.example.campuslink.commen.core.CoreViewHolder
import com.example.campuslink.databinding.AdapterDrawerLayoutBinding
import com.example.campuslink.model.DrawerlayoutContentData
import com.example.campuslink.viewModel.MainViewModel

class DrawerLayoutAdapter(vm: MainViewModel) :
    CoreAdapter<AdapterDrawerLayoutBinding, MainViewModel, DrawerlayoutContentData>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_drawer_layout
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        Glide.with(holder.itemView.context).load(mListData[position].icon)
            .error(R.drawable.ic_empty)
            .into(holder.binding.root.findViewById<ImageView>(R.id.iv_item))
        holder.binding.root.findViewById<TextView>(R.id.tv_label).text = mListData[position].title
        holder.itemView.setOnClickListener {
            when (mListData[position].title) {
                "关于我们" -> {
                    mViewModel?.jumpToAboutUsActivity()
                }

                "退出" -> {
                    mViewModel?.exit()
                }

                "图片生成" -> {
                    mViewModel?.jumpToImageProduceActivity()
                }

                "咨询问题" -> {
                    mViewModel?.jumpToInquiriesActivity()
                }
            }
        }
    }
}